package com.goktech.olala.core.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.goktech.olala.core.service.ICommentService;
import com.goktech.olala.server.dao.comment.CommentMapper;
import com.goktech.olala.server.pojo.comment.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wusq
 * 评论service层 实现类
 */
@Service("commentService")
public class CommentServiceImpl implements ICommentService {
    @Autowired
    CommentMapper commentMapper;

    /**
     * 查询所有评论
     * @param pageIndex
     * @param pageSize
     * @param comment
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<Comment> queryAllComment(int pageIndex, int pageSize, Comment comment) throws Exception {
        PageHelper.startPage(pageIndex, pageSize);
        List<Comment> infoList = commentMapper.selectAllByExample(comment);
        PageInfo<Comment> pageInfo = new PageInfo(infoList);
        return pageInfo;
    }
    /**
     * 删除对应评论
     * @param commentId
     * @return
     */
    @Override
    public int removeCommentById(Long commentId) {
        return commentMapper.deleteByPrimaryKey(commentId);
    }

    /**
     * 查询意见反馈
     * @param pageIndex
     * @param pageSize
     * @param comment
     * @return
     * @throws Exception
     */
    @Override
    public PageInfo<Comment> queryAdvices(int pageIndex, int pageSize, Comment comment) throws Exception {
        PageHelper.startPage(pageIndex, pageSize);
        List<Comment> infoList = commentMapper.selectByExample(comment);
        PageInfo<Comment> pageInfo = new PageInfo(infoList);
        return pageInfo;
    }

    /**
     * 查询详情
     * @param customerId
     * @return
     * @throws Exception
     */
    @Override
    public List<Comment> selectDetailAndCommentById(String customerId) throws Exception {
        return commentMapper.selectDetailAndCommentById(customerId);
    }
}
